﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Web.App_Code;
using QXBook.Model;
using System.Text;
using QXBook.Service;

namespace Web.SysManage
{
    public partial class Top : AdminBasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //检测管理员登录
            ServiceFactory.CreateInstance<AdminService>().CheckAdminLogin();
            ServiceFactory.CreateInstance<AdminService>().CheckAdminPop(-3);

            if (!Page.IsPostBack)
            {
                this.adminName.Text = base.adminInfo.NickName + (base.adminInfo.Role != null ? "(" + base.adminInfo.Role.RoleName + ")" : string.Empty);
                this.NavInit();
            }
        }

        /// <summary>
        /// 加载板块
        /// </summary>
        private void NavInit()
        {
            Dictionary<int, PopDomInfo> managepop = ServiceFactory.CreateInstance<AdminRuleService>().GetChildManagePopedomEntity(0);

            StringBuilder sb = new StringBuilder();
            if (managepop != null)
            {
                int i = 0;
                foreach (KeyValuePair<int, PopDomInfo> keyvalue in managepop)
                {

                    if (ServiceFactory.CreateInstance<AdminService>().CheckAdminPop(keyvalue.Value.PopID))
                    {
                        string text = "top_title1";
                        if (i == 0) text = "top_title";
                        sb.Append("<a id=\"m_" + i.ToString() + "\" href=\"Menu.aspx?ParendId=" + keyvalue.Value.PopID.ToString()
                                + "\" target=\"menu\" onclick=\"SelEmu(" + i.ToString() + ")\" class=\""
                                + text + " bold\">" + keyvalue.Value.PopName + "</a>\r\n");
                        i++;
                        if (i != managepop.Count) sb.Append("<a id=\"mm_" + i.ToString() + "\" class=\"top_title_m ttmbg\"></a>\r\n");
                    }
                }
            }
            sb.Append("<script type=\"text/javascript\">var Mnum=" + managepop.Count.ToString() + ";var SelecM=0;</script>");

            this.spNav.Text = sb.ToString();

        }
    }
}